package org.raymond.iworks.study.netty.atguigu.nio.reactor.mainsub;

import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class ReadWorker implements Runnable {
    private ByteBuffer byteBuffer;
    private ReadNotifyWorker readNotifyWorker;
    public ReadWorker(ByteBuffer byteBuffer, ReadNotifyWorker readNotifyWorker){
        this.byteBuffer = byteBuffer;
        this.readNotifyWorker = readNotifyWorker;
    }

    //获取客户端发送过来的消息
    @Override
    public void run() {
        //把缓冲区的byte[]转成字符串
        String msg = new String(byteBuffer.array()).trim();
        //输出该消息到控制台
        log.info("from 客户端：" + msg);
        //转发到其他客户端
        readNotifyWorker.notifyOtherClient(msg);
    }
}
